package com.bupt.uchouten.client.render.block.entity;

import com.bupt.uchouten.client.linkage.TenkaiVVInnerPixelmonRenderer;
import com.bupt.uchouten.common.block.TenkaiVigorousVineBlock;
import com.bupt.uchouten.common.block.entity.TenkaiVigorousVineBlockEntity;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraftforge.fml.ModList;

/**
 * @author wujichen158
 */
public class TenkaiVigorousVineRenderer extends AbstractBlockEntityRenderer<TenkaiVigorousVineBlockEntity> {

    private TenkaiVVInnerPixelmonRenderer innerPixelmonRenderer;

    public TenkaiVigorousVineRenderer(BlockEntityRendererProvider.Context dispatcher) {
        super(dispatcher);
        this.correctionAngles = 180;
        if (ModList.get().isLoaded("pixelmon")) {
            this.innerPixelmonRenderer = new TenkaiVVInnerPixelmonRenderer(dispatcher);
        }
    }

    @Override
    public void render(TenkaiVigorousVineBlockEntity blockEntity, BlockState state, double x, double y, double z, float partialTicks, PoseStack matrix, MultiBufferSource buffer, int combinedLight, int combinedOverlay) {
        if (ModList.get().isLoaded("pixelmon")) {
            this.innerPixelmonRenderer.render(blockEntity, state, x, y, z, partialTicks, matrix, buffer, combinedLight, combinedOverlay);
        }
    }

    @Override
    protected int getRotation(BlockState state) {
        if (state.getBlock() instanceof TenkaiVigorousVineBlock) {
            Direction facing = state.getValue(TenkaiVigorousVineBlock.FACING);
            return switch (facing) {
                case EAST -> 270;
                case SOUTH -> 180;
                case WEST -> 90;
                default -> 0;
            };
        }
        return 0;
    }
}
